<?php
/**
 *
 * PHP versions 5
 *
 * Copyright (C)
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 * of ERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software
 * Fundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
 *
 * @author Bastian Schröder <bs@chemanet.de>
 * @version 2007-08-06
 * @package rail
 */

function derive_icon( $pRailConnector, $pRailObject ){

	// rail_user
	if( $pRailObject instanceof rail_user )
		if( !$pRailObject->is_readable( $pRailConnector->get_user() ) )
			return "css/img/object_closed.png";
		else
			return "css/img/user.png";

	// rail page
	if( $pRailObject instanceof rail_page )
		if( !$pRailObject->is_readable( $pRailConnector->get_user() ) )
			return "css/img/document_closed.png";
		else
			return "css/img/page.png";

	// rail_document
	else if( $pRailObject instanceof rail_document )
		if( !$pRailObject->is_readable( $pRailConnector->get_user() ) )
			return "css/img/document_closed.png";
		else if( !$pRailObject->is_content_set() )
			return "css/img/mime_empty.png";
		else{
			$mimetype = $pRailObject->get_mimetype();
			if( $mimetype == 'application/pdf' )
				return "css/img/pdf.png";
			else if( $mimetype == 'text/html' )
				return "css/img/html.png";
			else if( substr( $mimetype, 0, 5 ) == 'text/' )
				return "css/img/document_txt.png";
			else if( substr( $mimetype, 0, 6 ) == 'image/' )
				return "css/img/document_image.png";
			else if( substr( $mimetype, 0, 6 ) == 'video/' )
				return "css/img/document_video.png";
			else if( substr( $mimetype, 0, 6 ) == 'audio/' )
				return "css/img/document_audio.png";
			else
				return "css/img/document.png";
		}

	// rail_root
	else if( $pRailObject instanceof rail_root )
		return "css/img/root.png";

	// rail_container
	else if( $pRailObject instanceof rail_container ){
		if( !$pRailObject->is_readable( $pRailConnector->get_user() ) )
			return "css/img/container_closed.png";
		else if( $pRailObject->is_readable( $pRailConnector->get_user() ) && $pRailObject->count_inventory() > 0 )
			return "css/img/container_full.png";
		else
			return "css/img/container_empty.png";
	}

	// all other
	else{
		if( !$pRailObject->is_readable( $pRailConnector->get_user() ) )
			return "css/img/object_closed.png";
		if( $pRailObject->is_readable( $pRailConnector->get_user() ) && $pRailObject->count_inventory() > 0 )
			return "css/img/object_full.png";
		else
			return "css/img/object_empty.png";
	}

} // End of derive_icon
?>